package org.meetunexpectedly.controller;

import org.meetunexpectedly.entity.video.VideoComment;
import org.meetunexpectedly.entity.vo.BasePage;
import org.meetunexpectedly.entity.vo.Result;
import org.meetunexpectedly.holder.UserHolder;
import org.meetunexpectedly.service.video.VideoCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;

/**
 * @Description: 视频评论控制类(暂时使用)
 * @Author: pupil
 * @Date: 2025/1/23 下午 4:49
 */
@RestController
@RequestMapping("/meetunexpectedly/videoComment")
public class VideoCommentController {

    @Autowired
    private VideoCommentService videoCommentService;


    /**
     * 评论评论
     *
     * @param videoId  视频id
     * @param content  评论内容
     * @return
     */
    @PostMapping("/{videoId}/{content}")
    public Result addComment(@PathVariable Long videoId, @PathVariable String content) {
        if (!videoCommentService.addComment(videoId, content, UserHolder.get())){
            return Result.error().message("发布评论失败");
        }
        return Result.ok().message("发布评论成功");
    }

    /**
     * 查询视频评论
     *
     * @param basePage 分页
     * @param videoId  视频id
     * @return
     */
    @GetMapping("/by/{videoId}")
    public Result getChildComment(BasePage basePage, @PathVariable Long videoId) {
        Collection<VideoComment> commentList = videoCommentService.getCommentByVideoId(basePage, videoId);
        return Result.ok().data(commentList);
    }

    /**
     * 删除评论
     *
     * @param commentId 评论id
     * @return
     */
    @DeleteMapping("/{commentId}")
    public Result deleteComment(@PathVariable Long commentId) {
        if (!videoCommentService.deleteCommentById(commentId, UserHolder.get())) {
            return Result.error().message("删除失败");
        }
        return Result.ok().message("删除成功");
    }
}
